package com.nightsoul.shiro.test.chapter5.hash;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.util.ByteSource;

public class MyHashedCredentialsMatcher extends HashedCredentialsMatcher {

	@Override
	protected Object getCredentials(AuthenticationInfo info) {
		if(info instanceof SimpleAuthenticationInfo) {
			SimpleAuthenticationInfo simpleAuthenticationInfo = (SimpleAuthenticationInfo) info;
			ByteSource salt = simpleAuthenticationInfo.getCredentialsSalt();
			return super.hashProvidedCredentials(simpleAuthenticationInfo.getCredentials(), salt, getHashIterations());
		}
		return super.getCredentials(info);
	}
}
